﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace TowerCraneMonitorClient.Migrations
{
    public partial class initialCreate : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "BaseicInfos",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    TowerId = table.Column<int>(nullable: false),
                    TowerGroupId = table.Column<int>(nullable: false),
                    Fall = table.Column<int>(nullable: false),
                    LocationX = table.Column<float>(nullable: false),
                    LocationY = table.Column<float>(nullable: false),
                    ForearmLength = table.Column<float>(nullable: false),
                    ReararmLength = table.Column<float>(nullable: false),
                    TowerHatHeight = table.Column<float>(nullable: false),
                    InstallationLongitude = table.Column<float>(nullable: false),
                    InstallationLatitude = table.Column<float>(nullable: false),
                    PointNorthAngle = table.Column<float>(nullable: false),
                    DeviceVersionNum = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BaseicInfos", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "DriverInfos",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    IDCard = table.Column<string>(nullable: true),
                    Name = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DriverInfos", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "EventAlarms",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    EventType = table.Column<int>(nullable: false),
                    EventTime = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EventAlarms", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "EventFaults",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    EventType = table.Column<int>(nullable: false),
                    EventTime = table.Column<DateTime>(nullable: false),
                    EventMessage = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EventFaults", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "LimitInfos",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    LeftAngleLimit = table.Column<float>(nullable: false),
                    RightAngleLimit = table.Column<float>(nullable: false),
                    RemoteLimit = table.Column<float>(nullable: false),
                    NearLimit = table.Column<float>(nullable: false),
                    HighLimit = table.Column<float>(nullable: false),
                    WeightLimit = table.Column<float>(nullable: false),
                    MaxExtentWeightLimit = table.Column<float>(nullable: false),
                    ForceLimit = table.Column<float>(nullable: false),
                    EarlyWarningWeightPercent = table.Column<float>(nullable: false),
                    AlarmWeightPercent = table.Column<float>(nullable: false),
                    ViolationWeightPercent = table.Column<float>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_LimitInfos", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MoniterInfos",
                columns: table => new
                {
                    Id = table.Column<string>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MoniterInfos", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "ReserveInfos",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Type = table.Column<int>(nullable: false),
                    Name = table.Column<string>(nullable: true),
                    ZoneId = table.Column<int>(nullable: false),
                    BuildingType = table.Column<int>(nullable: false),
                    X = table.Column<float>(nullable: false),
                    Y = table.Column<float>(nullable: false),
                    Width = table.Column<float>(nullable: false),
                    Height = table.Column<float>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ReserveInfos", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "RunDatas",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Time = table.Column<DateTime>(nullable: false),
                    Angle = table.Column<float>(nullable: false),
                    Extent = table.Column<float>(nullable: false),
                    Height = table.Column<float>(nullable: false),
                    Weight = table.Column<float>(nullable: false),
                    SafeWeight = table.Column<float>(nullable: false),
                    WeightPer = table.Column<float>(nullable: false),
                    Force = table.Column<float>(nullable: false),
                    ForcePer = table.Column<float>(nullable: false),
                    Wind = table.Column<float>(nullable: false),
                    Power = table.Column<int>(nullable: false),
                    Status = table.Column<int>(nullable: false),
                    ObliqueAngleX = table.Column<float>(nullable: false),
                    ObliqueAngleY = table.Column<float>(nullable: false),
                    LimitAlarmCode = table.Column<int>(nullable: false),
                    DriverInfoId = table.Column<long>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_RunDatas", x => x.Id);
                    table.ForeignKey(
                        name: "FK_RunDatas_DriverInfos_DriverInfoId",
                        column: x => x.DriverInfoId,
                        principalTable: "DriverInfos",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "WorkCycles",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    StartTime = table.Column<DateTime>(nullable: false),
                    EndTime = table.Column<DateTime>(nullable: false),
                    MaxWeight = table.Column<float>(nullable: false),
                    MaxWeightper = table.Column<float>(nullable: false),
                    MaxForce = table.Column<float>(nullable: false),
                    MaxForceper = table.Column<float>(nullable: false),
                    StartAngle = table.Column<float>(nullable: false),
                    EndAngle = table.Column<float>(nullable: false),
                    StartExtent = table.Column<float>(nullable: false),
                    EndExtent = table.Column<float>(nullable: false),
                    MaxExtent = table.Column<float>(nullable: false),
                    MinExtent = table.Column<float>(nullable: false),
                    StartHeight = table.Column<float>(nullable: false),
                    EndHeight = table.Column<float>(nullable: false),
                    MaxHeight = table.Column<float>(nullable: false),
                    MinHeight = table.Column<float>(nullable: false),
                    IsDriver = table.Column<int>(nullable: false),
                    Power = table.Column<int>(nullable: false),
                    MaxWind = table.Column<float>(nullable: false),
                    MaxElevation = table.Column<float>(nullable: false),
                    MinElevation = table.Column<float>(nullable: false),
                    Status = table.Column<int>(nullable: false),
                    DriverInfoId = table.Column<long>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_WorkCycles", x => x.Id);
                    table.ForeignKey(
                        name: "FK_WorkCycles_DriverInfos_DriverInfoId",
                        column: x => x.DriverInfoId,
                        principalTable: "DriverInfos",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "EventMessage",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    ActionType = table.Column<int>(nullable: false),
                    WarnLevel = table.Column<int>(nullable: false),
                    WarnType = table.Column<int>(nullable: false),
                    Force = table.Column<float>(nullable: false),
                    Angle = table.Column<float>(nullable: false),
                    Extent = table.Column<float>(nullable: false),
                    Height = table.Column<float>(nullable: false),
                    Weight = table.Column<float>(nullable: false),
                    EventAlarmId = table.Column<long>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EventMessage", x => x.Id);
                    table.ForeignKey(
                        name: "FK_EventMessage_EventAlarms_EventAlarmId",
                        column: x => x.EventAlarmId,
                        principalTable: "EventAlarms",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_EventMessage_EventAlarmId",
                table: "EventMessage",
                column: "EventAlarmId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_RunDatas_DriverInfoId",
                table: "RunDatas",
                column: "DriverInfoId");

            migrationBuilder.CreateIndex(
                name: "IX_WorkCycles_DriverInfoId",
                table: "WorkCycles",
                column: "DriverInfoId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "BaseicInfos");

            migrationBuilder.DropTable(
                name: "EventFaults");

            migrationBuilder.DropTable(
                name: "EventMessage");

            migrationBuilder.DropTable(
                name: "LimitInfos");

            migrationBuilder.DropTable(
                name: "MoniterInfos");

            migrationBuilder.DropTable(
                name: "ReserveInfos");

            migrationBuilder.DropTable(
                name: "RunDatas");

            migrationBuilder.DropTable(
                name: "WorkCycles");

            migrationBuilder.DropTable(
                name: "EventAlarms");

            migrationBuilder.DropTable(
                name: "DriverInfos");
        }
    }
}
